package com.yc.chatroom.ui.client.config;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ResourceBundle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

import com.gn.decorator.GNDecorator;
import com.yc.chatroom.ui.client.fx.SpringFXMLLoader;
import com.yc.chatroom.ui.client.fx.StageManager;
import com.yc.chatroom.ui.client.utils.ExceptionWriter;

import javafx.stage.Stage;

/** 
* <b>ClassName</b>: AppJavaConfig <br/> 
*
* <b>Description</b>: AppJavaConfig <br/> 
*
* <b>Date</b>: Apr 22, 2019 1:13:50 PM <br/> 
* 
* @author pdai
* @version Apr 22, 2019
*
*/
@Configuration
public class AppJavaConfig {
	
    @Autowired 
    SpringFXMLLoader springFXMLLoader;

    /**
     * Useful when dumping stack trace to a string for logging.
     * @return ExceptionWriter contains logging utility methods
     */
    @Bean
    @Scope("prototype")
    public ExceptionWriter exceptionWriter() {
        return new ExceptionWriter(new StringWriter());
    }

    @Bean
    public ResourceBundle resourceBundle() {
        return ResourceBundle.getBundle("Bundle");
    }
    
    /**
     * 关键：@Lazy(value = true)，没有这句话启动就报错：参数没人给传入
     * bean如果没有加@Scope("prototype"),表示单例，只会创建一次，哪怕这种带初始化参数的，
     * 后面即使传入不同的参数，返回的也是同一个对象
     * @param stage
     * @param decorator
     * @return
     * @throws IOException
     */
    @Bean
    @Lazy(value = true) //Stage only created after Spring context bootstap
    public StageManager stageManager(Stage stage, GNDecorator decorator) throws IOException {
        return new StageManager(springFXMLLoader, stage, decorator);
    }
    
    
}
